home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / program / misc / bgui12.lha / demos / filereq.c < prev    next >
C/C++ Source or Header  |  1995-05-20  |  7KB  |  163 lines

  1. ;/* Execute me to compile with DICE V3.0.
  2. dcc filereq.c -proto -mi -ms -mRR -3.0 -lbgui
  3. quit
  4. */
  5. /*
  6. **      FILEREQ.C
  7. **
  8. **      (C) Copyright 1995 Jaba Development.
  9. **      (C) Copyright 1995 Jan van den Baard.
  10. **          All Rights Reserved.
  11. **/
  12.  
  13. #include "democode.h"
  14.  
  15. #include <libraries/asl.h>
  16. #include <proto/utility.h>
  17.  
  18. /*
  19. **      Bulk GetAttr(). This really belongs in amiga.lib... I think.
  20. **/
  21. ULONG GetAttrs( Object *obj, ULONG tag1, ... )
  22. {
  23.         struct TagItem          *tstate = ( struct TagItem * )&tag1, *tag;
  24.         ULONG                    num = 0L;
  25.  
  26.         while ( tag = NextTagItem( &tstate ))
  27.                 num += GetAttr( tag->ti_Tag, obj, ( ULONG * )tag->ti_Data );
  28.  
  29.         return( num );
  30. }
  31.  
  32. /*
  33. **      Put up a simple requester.
  34. **/
  35. ULONG Req( UBYTE *gadgets, UBYTE *body, ... )
  36. {
  37.         struct bguiRequest      req = { NULL };
  38.  
  39.         req.br_GadgetFormat     = gadgets;
  40.         req.br_TextFormat       = body;
  41.         req.br_Flags            = BREQF_AUTO_ASPECT;
  42.         req.br_Underscore       = '_';
  43.  
  44.         return( BGUI_RequestA( NULL, &req, ( ULONG * )( &body + 1 )));
  45. }
  46.  
  47. VOID StartDemo( void )
  48. {
  49.         Object          *filereq;
  50.         ULONG            rc, dr, fl, pt, pa, l, t, w, h;
  51.  
  52.         /*
  53.         **      Present a simple requester.
  54.         **
  55.         **      NOTE: For some reason the size of the requester is not
  56.         **            saved when RTPatch (from reqtools) is active. When
  57.         **            I have some time left I'll take a look and try to
  58.         **            find out why.
  59.         **/
  60.         if ( ! Req( "_Continue|_Go Away!", ISEQ_C "This demo shows you how to use the BGUI\n"
  61.                                            "BOOPSI ASL interface. It pops a simple Load requester\n"
  62.                                            "and let's you play with it. After this the requester\n"
  63.                                            "type is changed into a Save requester. Ofcourse the\n"
  64.                                            "current path, requester size and position etc. is saved\n"
  65.                                            "while the object remains valid." ))
  66.                 return;
  67.         /*
  68.         **      Create a filerequester object.
  69.         **/
  70.         filereq = FileReqObject, ASLFR_DoPatterns, TRUE, EndObject;
  71.  
  72.         /*
  73.         **      Object OK?
  74.         **/
  75.         if ( filereq ) {
  76.                 /*
  77.                 **      Pop the requester.
  78.                 **/
  79.                 if ( ! ( rc = DoRequest( filereq ))) {
  80.                         /*
  81.                         **      Obtain attribute values.
  82.                         **/
  83.                         GetAttrs( filereq, FRQ_Drawer,          &dr,
  84.                                            FRQ_File,            &fl,
  85.                                            FRQ_Pattern,         &pt,
  86.                                            FRQ_Path,            &pa,
  87.                                            FRQ_Left,            &l,
  88.                                            FRQ_Top,             &t,
  89.                                            FRQ_Width,           &w,
  90.                                            FRQ_Height,          &h,
  91.                                            TAG_END );
  92.                         /*
  93.                         **      Dump 'm on the console.
  94.                         **/
  95.                         Tell( "Drawer                : %s\n"
  96.                               "File                  : %s\n"
  97.                               "Pattern               : %s\n"
  98.                               "Path                  : %s\n"
  99.                               "Left,Top,Width,Height : %ld,%ld,%ld,%ld\n",
  100.                               dr, fl, pt, pa, l, t, w, h );
  101.                 } else if ( rc == FRQ_CANCEL )
  102.                         /*
  103.                         **      Requester canceled.
  104.                         **/
  105.                         Tell("Canceled\n" );
  106.                 else
  107.                         /*
  108.                         **      Error.
  109.                         **/
  110.                         Tell("Error %ld\n", rc );
  111.  
  112.                 /*
  113.                 **      Make it a save requester.
  114.                 **/
  115.                 if ( ! ( rc = SetAttrs( filereq, ASLFR_DoSaveMode, TRUE, TAG_END ))) {
  116.                         /*
  117.                         **      Pop the requester.
  118.                         **/
  119.                         if ( ! ( rc = DoRequest( filereq ))) {
  120.                                 /*
  121.                                 **      Obtain attribute values.
  122.                                 **/
  123.                                 GetAttrs( filereq, FRQ_Drawer,          &dr,
  124.                                                    FRQ_File,            &fl,
  125.                                                    FRQ_Pattern,         &pt,
  126.                                                    FRQ_Path,            &pa,
  127.                                                    FRQ_Left,            &l,
  128.                                                    FRQ_Top,             &t,
  129.                                                    FRQ_Width,           &w,
  130.                                                    FRQ_Height,          &h,
  131.                                                    TAG_END );
  132.                                 /*
  133.                                 **      Dump 'm to the console.
  134.                                 **/
  135.                                 Tell( "Drawer                : %s\n"
  136.                                       "File                  : %s\n"
  137.                                       "Pattern               : %s\n"
  138.                                       "Path                  : %s\n"
  139.                                       "Left,Top,Width,Height : %ld,%ld,%ld,%ld\n",
  140.                                       dr, fl, pt, pa, l, t, w, h );
  141.                         } else if ( rc == FRQ_CANCEL )
  142.                                 /*
  143.                                 **      Requester canceled.
  144.                                 **/
  145.                                 Tell("Canceled\n" );
  146.                         else
  147.                                 /*
  148.                                 **      Error.
  149.                                 **/
  150.                                 Tell("Error %ld\n", rc );
  151.                 } else
  152.                         /*
  153.                         **      Error with SetAttrs().
  154.                         **/
  155.                         Tell( "Error %ld\n", rc );
  156.                 /*
  157.                 **      Dump the filerequester object.
  158.                 **/
  159.                 DisposeObject( filereq);
  160.         } else
  161.                 Tell( "unable to create filerequester object.\n" );
  162. }
  163.